package cn.hfjava.quickhit;

import java.util.Random;
public class Game {
    private Player player;

    public Game() {
        super();
    }

    public Game(Player player) {
        super();
        this.player = player;
    }

    public String printStr() {
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < LevelParam.levels[player.getLevelNo() - 1].getStrLength(); i++) {
            int rand = random.nextInt(6);
            switch (rand) {
                case 0:
                    buffer.append(">");
                    break;
                case 1:
                    buffer.append("<");
                    break;
                case 2:
                    buffer.append("*");
                    break;
                case 3:
                    buffer.append("&");
                    break;
                case 4:
                    buffer.append("%");
                    break;
                case 5:
                    buffer.append("#");
                    break;
            }
        }
        System.out.println(buffer.toString());
        return buffer.toString();
    }

    public void printResult(String out, String in) {

        if (out.equals(in)) {
            long currentTime = System.currentTimeMillis();
            if ((currentTime - player.getStartTime()) / 1000 > LevelParam.levels[player.getLevelNo() - 1].getTimeLimit()) {
                System.out.print("你输入太慢了，已经超时，退出！");
                System.exit(1);
            } else {
                player.setCurrScore(player.getCurrScore() + LevelParam.levels[player.getLevelNo() - 1].getPerScore());
                player.setElapsedTime((int) ((currentTime - player.getStartTime()) / 1000));
                System.out.println("输入正确，您的级别" + player.getLevelNo() + ",您的积分" + player.getCurrScore() + ",已用时间" + player.getElapsedTime() + "秒");
                if (player.getLevelNo() == 6) {
                    int score = LevelParam.levels[player.getLevelNo() - 1].getPerScore() * LevelParam.levels[player.getLevelNo() - 1].getStrTimes();
                    if (player.getCurrScore() == score) {
                        System.out.println("恭喜您，通关成功！");
                    } else {
                        System.out.println("输入错误，退出！");
                        System.exit(0);
                    }
                }
            }
        } else {
            System.out.println("输入错误");
            System.out.println("正确的是" + out);
            System.exit(0);
        }
    }
}









